package com.itheima;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class ServletDemo8 extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取信息
        String name = req.getParameter("name");
        String age = req.getParameter("age");
        String grades = req.getParameter("grades");
        //写入文件
        BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\a.txt",true));
        bw.write(name+","+age+","+grades);
        bw.newLine();
        bw.close();

        //响应信息
        PrintWriter writer = resp.getWriter();
        writer.print("save success");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
